package com.flyco.modules.returns.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.flyco.poi.excel.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.List;

@Data
public class OmsOrderReturnItemVO {

    /**
     * id
     */
    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "id")
    private Long id;

    /**
     * 退货申请id
     */
    @Excel(name = "退货申请id", width = 15)
    @ApiModelProperty(value = "退货申请id")
    private Long returnApplyId;
    /**
     * 退货商品id
     */
    @Excel(name = "退货商品id", width = 15)
    @ApiModelProperty(value = "退货商品id")
    private Long productId;
    /**
     * 商品货号
     */
    @Excel(name = "商品货号", width = 15)
    @ApiModelProperty(value = "商品货号")
    private String productSn;
    /**
     * 商品图片
     */
    @Excel(name = "商品图片", width = 15)
    @ApiModelProperty(value = "商品图片")
    private String productPic;
    /**
     * 商品名称
     */
    @Excel(name = "商品名称", width = 15)
    @ApiModelProperty(value = "商品名称")
    private String productName;
    /**
     * 退货数量
     */
    @Excel(name = "退货数量", width = 15)
    @ApiModelProperty(value = "退货数量")
    private Integer productCount;
    /**
     * 商品sku条码
     */
    @Excel(name = "商品sku条码", width = 15)
    @ApiModelProperty(value = "商品sku条码")
    private String productSkuCode;
    /**
     * 商品目前的单价
     */
    @Excel(name = "商品目前的单价", width = 15)
    @ApiModelProperty(value = "商品目前的单价")
    private java.math.BigDecimal price;
    /**
     * 商品目前的总金额
     */
    @Excel(name = "商品目前的总金额", width = 15)
    @ApiModelProperty(value = "商品目前的总金额")
    private java.math.BigDecimal totalAmount;
    /**
     * 对应的原单id
     */
    @Excel(name = "对应的原单id", width = 15)
    @ApiModelProperty(value = "对应的原单id")
    private String orderId;
    /**
     * 对应的原单明细id
     */
    @Excel(name = "对应的原单明细id", width = 15)
    @ApiModelProperty(value = "对应的原单明细id")
    private Long orderItemId;

    //购买数量（换算成最小包装单位后的）
    private Integer minUnitQuantity;

    @Excel(name = "单位", width = 15)
    private String productUnit;

    private Integer productSkuSpec;

    private String productSkuUnit;

    //实际收到基本单位的货品数量
    private Integer realUnitQuantity;

    private String productSpecUnit;

    public String getProductSpecUnit() {

        return this.productSkuSpec + this.productUnit + "/" + this.productSkuUnit;
    }

    //箱装价
    private BigDecimal skuUnitPrice;

    //单价
    private BigDecimal unitPrice;

    public BigDecimal getUnitPrice() {
        return this.price;
    }


    private String minUnitQuantityCount;

    public String getMinUnitQuantityCount() {
        return this.minUnitQuantity + productUnit;
    }

    //退货数量（箱）的格式
    private String returnSkuUnitCount;

    //退货数量（瓶）的格式
    private String returnUnitCount;

    public String getReturnSkuUnitCount() {
        Integer skuUnitCount = minUnitQuantity / productSkuSpec;
        return skuUnitCount + this.productSkuUnit;
    }

    public String getReturnUnitCount() {
        Integer unitCount = this.minUnitQuantity % this.productSkuSpec;
        return unitCount + productUnit;
    }


    //退货数量（箱）的格式
    private Integer returnSkuUnitCountNotUnit;

    //退货数量（瓶）的格式
    private Integer returnUnitCountNotUnit;

    public Integer getReturnSkuUnitCountNotUnit() {
        return minUnitQuantity / productSkuSpec;
    }

    public Integer getReturnUnitCountNotUnit() {
        return this.minUnitQuantity % this.productSkuSpec;

    }

    //拒绝售后的货品数量（按箱）
    private Integer refuseSkuUnitQuantity;

    public Integer getRefuseSkuUnitQuantity() {
        return refuseUnitQuantity == null ? 0 : refuseUnitQuantity / productSkuSpec;
    }

    //拒绝售后的货品数量（按瓶）
    private Integer refuseUnitQuantity;

    public Integer getRefuseUnitQuantity() {
        return refuseUnitQuantity == null ? 0 : refuseUnitQuantity % this.productSkuSpec;
    }

    //可再次利用的货品数量（按箱）返仓
    private Integer reuseSkuUnitQuantity;

    public Integer getReuseSkuUnitQuantity() {
        return reuseUnitQuantity == null ? 0 : reuseUnitQuantity / productSkuSpec;
    }

    //可再次利用的货品数量（按瓶）返仓
    private Integer reuseUnitQuantity;

    public Integer getReuseUnitQuantity() {
        return reuseUnitQuantity == null ? 0 : reuseUnitQuantity % this.productSkuSpec;
    }

    //报废的货品数量（按箱）
    private Integer uselessSkuUnitQuantity;

    public Integer getUselessSkuUnitQuantity() {
        return uselessUnitQuantity == null ? 0 : uselessUnitQuantity / productSkuSpec;
    }

    //报废的货品数量（按瓶）
    private Integer uselessUnitQuantity;

    public Integer getUselessUnitQuantity() {
        return uselessUnitQuantity == null ? 0 : uselessUnitQuantity % this.productSkuSpec;
    }


    //退货数量（箱）的格式
    private Integer realReturnSkuUnitCount;

    //退货数量（瓶）的格式
    private Integer realReturnUnitCount;

    @ApiModelProperty(value = "小计金额(报废+返仓)")
    private BigDecimal totalRealAmount;

    @ApiModelProperty(value = "退换货凭证")
    private String returnCertificate;

    private List<ReturnFileVO> returnFileList;

    @ApiModelProperty(value = "退货原因")
    private String reason;

    public List<ReturnFileVO> getReturnFileList() {

        if (StringUtils.isEmpty(returnCertificate)) {
            return null;
        }

        List<ReturnFileVO> fileVOList = JSONObject.parseArray(returnCertificate, ReturnFileVO.class);

        return fileVOList;

    }

    @ApiModelProperty(value = "批次号")
    private String batchNo;
}
